#region Namespaces

using System;
using System.Xml;

#endregion

namespace Vibstudio.X4NET.Xml.Linq
{
    public class XDocumentType : XNode
    {
        private string _intSubset;

        private string _name;

        private string _pubid;

        private string _sysid;

        public XDocumentType(string name, string publicId, string systemId, string internalSubset)
        {
            _name = name;
            _pubid = publicId;
            _sysid = systemId;
            _intSubset = internalSubset;
        }

        public XDocumentType(XDocumentType other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }
            _name = other._name;
            _pubid = other._pubid;
            _sysid = other._sysid;
            _intSubset = other._intSubset;
        }

        public string Name
        {
            get { return _name; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                _name = value;
            }
        }

        public string PublicId
        {
            get { return _pubid; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                _pubid = value;
            }
        }

        public string SystemId
        {
            get { return _sysid; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                _sysid = value;
            }
        }

        public string InternalSubset
        {
            get { return _intSubset; }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                _intSubset = value;
            }
        }

        public override XmlNodeType NodeType
        {
            get { return XmlNodeType.DocumentType; }
        }

        public override void WriteTo(XmlWriter writer)
        {
            XDocument doc = Document;
            XElement root = doc.Root;
            if (root != null)
            {
                writer.WriteDocType(root.Name.LocalName, _pubid, _sysid, _intSubset);
            }
        }
    }
}